<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>{{title}}</title>

</head>

<body>
    <ul>
        {{each data as value index}}
        <li><a href="/theme1.html?id={{value.id}}" id="theme" data-id="{{value.id}}">{{value.content}} {{value.id}}</a></li>
        {{/each}}



    </ul>
    <a href="/posting">发帖</a>
    <a class="more_data">更多数据</a>

    <a href="/subscribe">查看订阅</a>
    <a href="/mycomment">我的留言</a>
    <a href="/mytheme">我的主题</a>

    <a href="/history.html" id="history">查看浏览历史</a>

    <button id="clear">清除浏览历史</button>


</body>

</html>
<script src="/js/jquery.min.js"></script>
<script src="/js/jroll.js"></script>
<script src="/js/jroll-infinite.js"></script>
<script src="/js/jroll-pulldown.js"></script>
<script>
    //   

    $('li').on('click', '#theme', function () {
        // console.log(window.localStorage.getItem('history_list'));

        var array;
        var historyarray = JSON.parse(window.localStorage.getItem("history_list"));

        if (historyarray == null) {
            array = [];
        } else {
            array = historyarray;
            console.log(array);
        }
        var theme_id = $(this).data('id');
        for (var i = 0; i < array.length; i++) {
            if (array[i] == theme_id) {
                array.splice(i, 1);
            }

        }

        console.log(typeof theme_id);
        array.push(theme_id);
        window.localStorage.setItem('history_list', JSON.stringify(array));
        console.log(historyarray);

    })



    $('#clear').click(function () {
        localStorage.clear('history_list');
    });
</script>